<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>全选反选</title>
	</head>
	<body>
		<input type="checkbox" id="all" />全选<br>
		<hr/>
		<input type="checkbox" class="box" />电脑<br>
		<input type="checkbox" class="box" />手机<br>
		<input type="checkbox" class="box" />电视<br>
		<script>
			var all =document.getElementById('all');
			var box =document.getElementsByClassName('box');
			all.addEventListener('click',myfun,false);
			function myfun(){
				for(var i=0;i<box.length;i++){
					box[i].checked=event.target.checked;
				}
			}
		</script>
	</body>
</html>
